/**
 * 收割
 */

import { Context } from "../class/Context";
import { Hurt } from "../class/Hurt";
import { Method } from "../class/Method";
import { RoleStatus } from "../class/Role";

export class Harvest extends Method {
    static methodName = "收割"
    public CD: number = 30E3;
    public describe: string = "对目标造成 150%(MA) 的法术伤害 + 20%(itLossHP) 真实伤害;如果成功击杀敌人，则技能CD将重置为 2S。否则，则对自身造成 20%(HP) 真实伤害。";
    public invoke(context: Context) {
        const itId = context.nextParam();
        const it = this.masterRole.game.getRole(itId);
        // 计算伤害
        const MA = Math.floor(this.masterRole.getMagicAttack() * 1.5)
        const TD = Math.floor((it.getMAXHP() - it.getHP()) * 0.2)
        const hurt = new Hurt(0, MA, TD)

        it.onHurt(this.masterRole, hurt);
        if (it.getStatus() == RoleStatus.Die) {
            this.callTime = Date.now() - 2;// 设置上一次调用时间为 2 秒以前
            this.masterRole.message.add("击杀成功。")
        } else { // 击杀失败
            const TD = Math.floor(this.masterRole.getHP() * 0.2);
            this.masterRole.onHurt(it, new Hurt(0, 0, TD))
            this.masterRole.message.add("击杀失败。")
        }
    }

}